import openpyxl


class ExcelTools:
    def __init__(self, file_path):
        """
        初始化：指定file_path
        """
        self.excel_obj = openpyxl.load_workbook(file_path)

    def excel_read(self, sheet_name):
        sheet = self.excel_obj[sheet_name]
        res = []
        for value in sheet.values:
            # print(value)
            res.append(value)
        self.excel_obj.close()
        return res

    def excel_write(self, sheet_name, cell_row, cell_column, cell_value):
        sheet = self.excel_obj[sheet_name]
        sheet.cell(row=cell_row, column=cell_column, value=cell_value)

    def excel_save(self, file_path):
        self.excel_obj.save(file_path)

    def excel_close(self):
        self.excel_obj.close()


if __name__ == '__main__':
    et = ExcelTools('../data/apidata_new.xlsx')
    res = et.excel_read('2.6耗材柜的接口')
    a = 1
    for i in res:
        print(a)
        print(i)
        a = a + 1
    # et.excel_write('2.6耗材柜的接口', 2, 5, 'None')
    # et.excel_save('../data/apidata.xlsx')
    et.excel_close()

    # res = et.excel_read('../data/apidata.xlsx', '高值耗材柜3.0')
    # for i in res:
    #     print(i)
